﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DAO;
using DTO;
namespace Presentation
{
    public partial class UserControlHangganhet : UserControl
    {
        public UserControlHangganhet()
        {
            InitializeComponent();
        }

        private void btnThoat_Click(object sender, EventArgs e)
        {
            this.Visible = false;
        }

        private void btnIn_Click(object sender, EventArgs e)
        {
        }

        private void UserControlHangganhet_Load(object sender, EventArgs e)
        {
            try
            {
                DuocPhamDao dpDao = new DuocPhamDao();
                DuocPhamDto[] dpDto = dpDao.SelectHangganhet();

                dgvHangganhet.AutoGenerateColumns = false;
                dgvHangganhet.DataSource = dpDto;
                float sum = 0;
                for (int i = 0; i < dgvHangganhet.Rows.Count; i++)
                {
                    sum = sum + float.Parse(dgvHangganhet.Rows[i].Cells[5].Value.ToString());
                }
                txtTongtien.Text = Convert.ToDecimal(sum).ToString();
            }
            catch (Exception)
            {
                MessageBox.Show("Không có dữ liệu!");
            }
        }

        private void btnLuuBaoCao_Click(object sender, EventArgs e)
        {
            Utils.ExportToExcel(dgvHangganhet);
        }

        private void dgvHangganhet_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e)
        {
            DataGridView grv = (DataGridView)sender;
            Utils.MakeSothutuColumn(grv, "itemStt"); ;
        }
    }
}
